<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
    <div class="ui-layout-west">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 用户列表
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
    
    <div class="ui-layout-center">
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="user-form">
                        <input type="hidden" id="userId" name="userId">
                        <div class="select-list">
                            <ul>
                                <li class="select-time">
                                    <label>回复时间： </label>
                                    <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                    <span>-</span>
                                    <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>
                
                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="addTabDialog()" shiro:hasPermission="system:communication:add">
                        <i class="fa fa-plus"></i> 回复
                    </a>
                </div>
                
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
    
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var removeFlag = [[${@permission.hasPermi('system:communication:remove')}]];
        var prefix = ctx + "business/communication";

        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185 });
             // 回到顶部绑定
            if ($.fn.toTop !== undefined) {
                var opt = {
                    win:$('.ui-layout-center'),
                    doc:$('.ui-layout-center')
                };
                $('#scroll-up').toTop(opt);
            }
            queryUserList();
            queryDeptTree();
            $('.tree_1').click();
        });

        function queryUserList() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                sortName: "createTime",
                sortOrder: "desc",
                modalName: "用户",
                columns: [{
                    checkbox: true
                },{
                    field: 'userId',
                    title: '用户ID'
                },
                {
                    field: 'userName',
                    title: '用户名称'
                },
                {
                    field: 'adminUserId',
                    title: '管理员ID'
                },
                {
                    field: 'adminUserName',
                    title: '管理员名称'
                },
                {
                    field: 'content',
                    title: '内容'
                },
                {
                    field: 'createTime',
                    title: '发布时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        if (row.userId != 1) {
                            var actions = [];
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.communicationId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                            return actions.join('');
                        } else {
                            return "";
                        }
                    }
                }]
            };
            $.table.init(options);
        }
        
        function queryDeptTree(){
            var url = ctx + "business/communication/userList";
            var options = {
                url: url,
                expandLevel: 2,
                onClick : zOnClick
            };
            $.tree.init(options);
            
            function zOnClick(event, treeId, treeNode) {
                $("#userId").val(treeNode.id);
                $.table.search();
            }
        }
        
        function addTabDialog(){
             layer.open({
                    id:1,
                    type: 1,
                    title:'请输入回复内容',
                    style: 'width:80%;height:auto;',
                    content: "<div style='display:flex;justify-content:center;'><textarea id='area' style='width:100%;height:135px;'></textarea></div>",
                    btn:['保存','取消'],
                    yes:function (index,layero) {
                        if($("#userId").val() == ""){
                            $.modal.alertWarning("请在左侧选择用户后再进行回复！");
                            return;
                        }
                         //获取输入框里面的值
                        var closeContent = top.$("#area").val() || $("#area").val();
                        if(closeContent){
                            console.log(closeContent);
                        }
                        layer.close(index);
                        // 在这里提交数据
                        var postData = {};
                        postData.userId = $("#userId").val();
                        postData.content = closeContent;
                        postData.userType = "1";
                        $.ajax({
                            type: "post",
                            url: ctx + "business/communication/addCommunication",
                            data: JSON.stringify(postData),
                            dataType: "json",
                            contentType: 'application/json;charset=UTF-8',
                            success: function(data){
                                $.table.search();
                            }
                        });
                    },
                    no:function (index,layero) {
                         layer.close(index);
                    }
                });

        }

    </script>
</body>
</html>